<?php

// deal with user details


function fetch_user_details($user_id) {
  // Make the query.
  $query = "SELECT first_name, last_name, title, address1, address2, address3, address4, post_code, home_phone, work_phone, mobile_phone, email, email_allowed, election_year, stop_year, is_current, admin_email_ok, is_committee FROM user_details WHERE user_id=$user_id";
  $result = mysql_query ($query);
  return mysql_fetch_array($result);
}

function fetch_user_blurb($user_id) {
  $query = "SELECT blurb FROM user_blurb WHERE user_id=$user_id";
  $result = mysql_query ($query);
  return mysql_fetch_array($result);
}

function fetch_user_thing_results($thing, $user_id, $level) {
  $query = "SELECT all_{$thing}s.{$thing} FROM all_{$thing}s, user_{$thing} WHERE user_{$thing}.user_id=$user_id AND user_{$thing}.level=$level AND user_{$thing}.{$thing}_id=all_{$thing}s.{$thing}_id ORDER BY all_{$thing}s.{$thing}";
  $result = mysql_query($query)  or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
  return $result;
}

// somewhat misleadingly named...
function fetch_user_name($user_id) {
  $ans = FALSE;
  $query = "SELECT first_name, last_name, email_allowed, email FROM user_details WHERE user_id=$user_id";
  $result = @mysql_query ($query);
  if ($result) {
    $ans= mysql_fetch_array($result);
  }
  return $ans;
}

function fetch_user_info($user_id) {
  $ans = FALSE;
  $query = "SELECT login, level FROM users WHERE user_id = $user_id";
  $result = mysql_query($query)  or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
  if ($result) {
    $ans= mysql_fetch_array($result);
  }
  return $ans;

}

?>

